package cn.hackcloud.annotation.condition;

import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

import cn.hackcloud.annotation.bean.Gray;

public class MyImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar {
	/**
	 * AnnotationMetadata：当前类的注解信息 BeanDefinitionRegistry：BeanDefinition注册类
	 */
	public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
		boolean b1 = registry.containsBeanDefinition("cn.hackcloud.annotation.bean.Red");
		boolean b2 = registry.containsBeanDefinition("cn.hackcloud.annotation.bean.Blue");
		if (b1 && b2) {
			BeanDefinition beanDefinition = new RootBeanDefinition(Gray.class);
			registry.registerBeanDefinition("gray", beanDefinition);
		}

	}

}
